package com.windward.vii.dao.mapper;

import com.windward.vii.dao.entity.AppBanner;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface AppBannerMapper {
    @Delete({
        "delete from app_banner",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into app_banner (id, type, ",
        "title, img_url, link, ",
        "begin_time, end_time, ",
        "create_time, update_time, ",
        "enable)",
        "values (#{id,jdbcType=BIGINT}, #{type,jdbcType=TINYINT}, ",
        "#{title,jdbcType=VARCHAR}, #{imgUrl,jdbcType=VARCHAR}, #{link,jdbcType=VARCHAR}, ",
        "#{beginTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ",
        "#{enable,jdbcType=BIT})"
    })
    int insert(AppBanner record);

    int insertSelective(AppBanner record);

    @Select({
        "select",
        "id, type, title, img_url, link, begin_time, end_time, create_time, update_time, ",
        "enable",
        "from app_banner",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    AppBanner selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(AppBanner record);

    @Update({
        "update app_banner",
        "set type = #{type,jdbcType=TINYINT},",
          "title = #{title,jdbcType=VARCHAR},",
          "img_url = #{imgUrl,jdbcType=VARCHAR},",
          "link = #{link,jdbcType=VARCHAR},",
          "begin_time = #{beginTime,jdbcType=TIMESTAMP},",
          "end_time = #{endTime,jdbcType=TIMESTAMP},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP},",
          "enable = #{enable,jdbcType=BIT}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(AppBanner record);

    // ***************

    @Select({
            "select",
            "id, type, title, img_url, link, begin_time, end_time, create_time, update_time, ",
            "enable",
            "from app_banner",
            "where type = 1 and enable = 1"
    })
    @ResultMap("BaseResultMap")
    List<AppBanner> getRecommendBanner();

    @Select({
            "select",
            "id, type, title, img_url, link, begin_time, end_time, create_time, update_time, ",
            "enable",
            "from app_banner",
            "where type = 2 and enable = 1"
    })
    @ResultMap("BaseResultMap")
    List<AppBanner> getNewestBanner();
}